package com.googlecode.cswish.util;

import java.util.Collection;

import com.googlecode.cswish.struts.ContextHolder;
import com.googlecode.cswish.struts.spring.ObjectFactory;

public class WebsiteUtil {
	
	private static IWebsiteService websiteService;
	
	public static String getKeyPrefix() {
		return "#" + ContextHolder.get().getSiteName() + "#";
	}
	
	public static String getKey(String key) {
		return getKey(ContextHolder.get().getSiteName(), key);
	}
	
	public static String getKey(String siteName, String key) {
		if (siteName == null) {
			return null;
		} else {
			return "#" + siteName + "#" + key;
		}
	}
	
	// TODO: put this method here?
	public static Collection<String> getWebsites() {
		return getWebsiteService().getWebsiteNames();
	}

	private static IWebsiteService getWebsiteService() {
		if (websiteService == null) {
			websiteService = ObjectFactory.getInstance().getBean(IWebsiteService.class, false);
		}
		return websiteService;
	}
}
